﻿Imports EShop.VBClass

Partial Class webprogram_admins
    Inherits System.Web.UI.Page

    Function loadAdmins() As String
        Dim strBd As New StringBuilder
        Dim condition As String = ""
        Dim dtCLst As Data.DataTable = GetDataTableN("admins", "*", condition, "adm_lsLogintime desc")
        If dtCLst IsNot Nothing Then
            Dim rCount As Integer = dtCLst.Rows.Count
            Dim cid, adm_UID, adm_Name, adm_Role, adm_Logintimes, adm_lsLogintime, adm_lsLoginIP, adm_Lockstr As String
            Dim lockLink As String = "", adm_Lock As Boolean, adm_LockV As Integer
            Dim role_Name As String, roleID As String = Session("admin_role")

            For i As Integer = 0 To rCount - 1
                cid = dtCLst.Rows(i)("id")
                adm_UID = dtCLst.Rows(i)("adm_UID")
                adm_Name = dtCLst.Rows(i)("adm_Name")
                adm_Role = dtCLst.Rows(i)("adm_Role")
                adm_Logintimes = dValue(dtCLst.Rows(i)("adm_Logintimes"), 0)
                adm_lsLogintime = dValue(dtCLst.Rows(i)("adm_lsLogintime"), "--")
                adm_lsLoginIP = dValue(dtCLst.Rows(i)("adm_lsLoginIP"), "")
                adm_Lock = dValue(dtCLst.Rows(i)("adm_Lock"), False)
                If adm_Lock Then
                    'adm_Lockstr = "是"
                    lockLink = "解锁"
                Else
                    'adm_Lockstr = "否"
                    lockLink = "锁定"
                End If
                adm_Lockstr = getYesNo(adm_Lock)
                adm_LockV = getYesNoN(adm_Lock)
                If adm_LockV = 0 Then
                    adm_LockV = 1
                Else
                    adm_LockV = 0
                End If
                role_Name = RoleName(adm_Role)

                If adm_Role >= roleID Then
                    strBd.Append("<tr>")
                    strBd.AppendFormat("<td>{0}</td>", adm_UID) 'title
                    strBd.AppendFormat("<td>{0}</td>", adm_Name) 'xName 
                    strBd.AppendFormat("<td>{0} </td>", role_Name)
                    strBd.AppendFormat("<td>{0} </td>", adm_Lockstr)
                    strBd.AppendFormat(" <td>{0}</td>", adm_Logintimes) '
                    strBd.AppendFormat(" <td>{0}</td>", adm_lsLogintime) '
                    strBd.AppendFormat("  <td>{0} &nbsp; <a href='logview.aspx?uid={1}'>历史</a></td>", adm_lsLoginIP, cid) 'IP
                    If adm_Role > roleID Or Session("admin_UID") = "wen" Then
                        strBd.AppendFormat("  <td><a href=""?lid={0}&lv={1}"">{2}</a>  &nbsp;<a href=""adminadd.aspx?aid={0}"">修改</a> &nbsp; <a href=""?did={0}&dtit={1}"">删除</a></td>", cid, adm_LockV, lockLink)
                    Else

                        If Session("admin_UID") = adm_UID Then
                            strBd.AppendFormat("  <td><span class=gray>{0}</span>  &nbsp;<a href=""adminadd.aspx?aid={1}"">修改</a> &nbsp; <span class=gray>删除</span></td>", lockLink, cid)
                        Else
                            strBd.AppendFormat("  <td><span class=gray>{0}</span>  &nbsp;<span class=gray>修改</span> &nbsp; <span class=gray>删除</span></td>", lockLink)
                        End If


                    End If
                    strBd.Append("</tr>" & vbCrLf)
                End If
            Next

        End If
        Return strBd.ToString
    End Function

    Sub delAdmins(delId As Integer)
        Dim sqlD As String = "delete from admins where id=" & delId
        Dim dTitle As String = getFiledvalue("adm_name", "admins", " id=" & delId)
        If ExecuteSQL(sqlD) Then
            ExecuteJSalert(Me, "已成功删除管理员:" & dTitle)
        Else
            ExecuteJSalert(Me, "功删除管理员出错了：" & dTitle)

        End If
    End Sub

    Sub LockAdmins(lockId As Integer, lockValue As Integer)
        Dim sqlD As String = "update   admins set adm_lock=" & lockValue & "  where id=" & lockId
        Dim dTitle As String = getFiledvalue("adm_name", "admins", " id=" & lockId)
        Dim lok As String = IIf(lockValue = 0, "解锁", "锁定")
        If ExecuteSQL(sqlD) Then
            ExecuteJSalert(Me, "已成功" & lok & "管理员:" & dTitle)
        Else
            ExecuteJSalert(Me, lok & "管理员出错了：" & dTitle)

        End If
    End Sub

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        checkSessionTimeout(Me)
        checkData(Me)

        Dim did As String = dValue(Request("did"), "")
        Dim lid As String = dValue(Request("lid"), "")
        Dim lv As String = dValue(Request("lv"), "")
        If did <> "" Then
            delAdmins(did)
        ElseIf lid <> "" And lv <> "" Then
            LockAdmins(lid, lv)
        End If
        Me.tBody1.InnerHtml = loadAdmins()


    End Sub
End Class
